import Vue from "vue";
import Router from "vue-router";
import NotFound from "./views/404"
import NPorgress from "nprogress"
import "nprogress/nprogress.css"

Vue.use(Router);

const  router =  new Router({
    mode: "history", //去掉路由中的#号
    base: process.env.BASE_URL,
    routes: [
        {
            path: "/user",
            component: () =>
                import(/* webpackChunkName: "layout" */ "./layouts/UserLayout"),
            children: [
                {
                    path: "/user",
                    redirect: "/user/login"
                },
                {
                    path: "/user/login",
                    name: "login",
                    component: () =>
                        import(/* webpackChunkName: "user" */ "./views/user/login")
                },
                {
                    path: "/user/register",
                    name: "register",
                    component: () =>
                        import(/* webpackChunkName: "user" */ "./views/user/register")
                }
            ]
        },
        {
            path: "/",
            component:  () =>
                import(/* webpackChunkName: "layout" */ "./layouts/BasicLayout"),
            children: [
                // dashboard
                {
                    path: "/dashboard",
                    redirect: "/dashboard/analysis"
                },
                {
                    path: '/dashboard',
                    name: 'dashboard',
                    component: {render: h=>h("router-view")},
                    children : [
                        {
                            path: '/dashboard/analysis',
                            name: 'analysis',
                            component: () =>
                                import(/* webpackChunkName: "dashboard" */ "./views/Dashboard/Analysis")
                        }
                    ]

                },
                // forms
                {
                    path: '/form',
                    name: 'form',
                    component: {render: h=>h("router-view")},
                    children: [
                        {
                            path: '/form/basic-form',
                            name: 'basicForm',
                            component: () =>
                                import(/* webpackChunkName: "form" */ "./views/Forms/BasicForm")
                        },
                        {
                            path: '/form/step-form',
                            name: 'stepForm',
                            component:  () =>
                                import(/* webpackChunkName: "form" */ "./views/Forms/StepForm"),
                            children: [
                                {
                                    path: '/form/step-form',
                                    redirect:"/form/step-form/info"
                                },
                                {
                                    path: '/form/step-form/info',
                                    name: 'info',
                                    component:  () =>
                                        import(/* webpackChunkName: "form" */ "./views/Forms/StepForm/Step1"),
                                },
                                {
                                    path: '/form/step-form/confirm',
                                    name: 'confirm',
                                    component:  () =>
                                        import(/* webpackChunkName: "form" */ "./views/Forms/StepForm/Step2"),
                                },
                                {
                                    path: '/form/step-form/result',
                                    name: 'result',
                                    component:  () =>
                                        import(/* webpackChunkName: "form" */ "./views/Forms/StepForm/Step3"),
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        /*  404页面配置 */
        {
            path: "*",
            name: "404",
            component: NotFound
        }
    ]
});

/**
 * 状态条 NPorgress
 */
router.beforeEach((to, from , next) => {
    NPorgress.start();
    next();
});

router.afterEach(() => {
    NPorgress.done();
});

export  default  router

